angular.module('mamApp').controller('roleController', ['$scope', '$state', '$uibModal', 'SystemManager','ImsDialog','RoleManager',
    function ($scope, $state, $uibModal, SystemManager,ImsDialog,RoleManager) {


        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10
        };

        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }


        $scope.categoryChange=function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name,$scope.search)

        }


        $scope.delete=function (item) {
            ImsDialog.open({title:"角色删除",message:"确定删除"+item.roleName+"吗？"}).then(function (a) {
                if(a=="ok"){
                    RoleManager.roleDelete(item.roleId).then(function (result) {
                        if(result.data.c=="s"){
                            $state.reload();
                        }
                    })
                }
            })

        }

        $scope.noPermission=false;
        RoleManager.roleList([$scope.search.pageNo,$scope.search.pageSize]).then(function (result) {
            if(result.data.c=="n"){
                $scope.noPermission=true;
            }else{
                $scope.noPermission=false;
                $scope.roleList =result.data.pageList;
                $scope.paginationConf.totalItems=result.data.total;
            }

        })




    }])

